package com.lu.core.auto;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.lu.core.annotations.EnableDataScope;
import com.lu.core.aop.DataPermissionInterceptor;
import com.lu.core.support.DataScopePermissionAbstract;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import javax.annotation.PostConstruct;

/**
 * @program RCS
 * @description: 日志配置开启
 * @author: zhanglu
 * @create: 2021-03-09 15:59:00
 */
@Slf4j
@Configuration
public class DataScopeProxyAutoConfiguration implements ImportAware {

    /**
     * 启动注解参数
     */
    public static AnnotationAttributes enableDataScope;

    @Override
    public void setImportMetadata(AnnotationMetadata importMetadata) {
        try {
            //获取注解参数
            this.enableDataScope = AnnotationAttributes.fromMap(
                    importMetadata.getAnnotationAttributes(EnableDataScope.class.getName(), false));
           if (this.enableDataScope == null) {
                log.info("@EnableDataScope is not present on importing class");
                return;
            }
           String platform = DataScopeProxyAutoConfiguration.enableDataScope.getString("platform");
           log.info(StrUtil.format("{}数据权限开启", platform));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
